package com.fairytask.items
{
	import com.fairytask.utils.Vec2D;
	
	import flash.geom.ColorTransform;
	
	import starling.display.MovieClip;
	import starling.display.Sprite;
	
	public class Virus extends Avatar
	{
		internal var _scaleYMin:Number=0.4;
		
		internal var _scaleTime:Number=0.3;
		
		internal var _scaleYMax:Number=1.2;
		
		public var feelerDist:uint=2000;
		
		internal var _toCell:Cell;
		
		internal var _scaleXMin:Number=0.8;
		
		internal var _scalingOut:Boolean=true;
		
		internal var _maxAngVel:uint=600;
		
		public var fromCell:Cell;
		
		public var value:Number=1;
		
		internal var _mc:MovieClip;
		
		internal var _scaleXMax:Number=2.3;
		
		internal var _maxVel:uint=100;
		
		internal var _offset:Vec2D;
		
		internal var _unitType:int=-1;
		
		public function Virus()
		{
			this._offset = new Vec2D();
			super();
			this._mc = new MovieClip();
			var loc1:*=Math.random();
			this._mc.scaleX = this._scaleXMin + (this._scaleXMax - this._scaleXMin) * loc1;
			this._mc.scaleY = this._scaleYMax - (this._scaleYMax - this._scaleYMin) * loc1;
			this.addChild(this._mc);
		}
		
		public function set toCell(arg1:Cell):void
		{
			var loc1:*=null;
			this._toCell = arg1;
			loc1 = this._toCell.vec;
			loc1.x = loc1.x + (-this._toCell.radius * 0.6 + Math.random() * this._toCell.radius * 1.2);
			loc1.y = loc1.y + (-this._toCell.radius * 0.6 + Math.random() * this._toCell.radius * 1.2);
			this._offset.x = this._toCell.x - loc1.x;
			this._offset.y = this._toCell.y - loc1.y;
			pointAt(this._toCell.x, this._toCell.y);
			return;
		}
		
		public function updateMove(arg1:Number):void
		{
			if (!this._toCell) 
			{
				return;
			}
			var loc1:*=this._toCell.vec.addVec(this._offset);
			var loc2:*=loc1.subVec(this.posV).normalized;
			var loc3:*=0;
			var loc4:*=0;
			loc3 = arg1 / this._scaleTime * (this._scaleXMax - this._scaleXMin);
			loc4 = arg1 / this._scaleTime * (this._scaleYMax - this._scaleYMin);
			if (this._scalingOut) 
			{
				this._mc.scaleX = this._mc.scaleX + loc3;
				this._mc.scaleY = this._mc.scaleY - loc4;
				if (this._mc.scaleX >= this._scaleXMax) 
				{
					this._scalingOut = false;
					this._mc.scaleX = this._scaleXMax;
					this._mc.scaleY = this._scaleYMin;
				}
				this.vel = (this._mc.scaleX - this._scaleXMin) / (this._scaleXMax - this._scaleXMin) * this._maxVel / 2;
			}
			else 
			{
				this._mc.scaleX = this._mc.scaleX - loc3;
				this._mc.scaleY = this._mc.scaleY + loc4;
				if (this._mc.scaleX <= this._scaleXMin) 
				{
					this._scalingOut = true;
					this._mc.scaleX = this._scaleXMin;
					this._mc.scaleY = this._scaleYMax;
				}
				this.vel = (this._mc.scaleX - this._scaleXMin) / (this._scaleXMax - this._scaleXMin) * this._maxVel;
			}
			this.angVel = this.ov.normal.dot(loc2) * this._maxAngVel;
			return;
		}
		
		public function get toCell():Cell
		{
			return this._toCell;
		}
		
		public function get unitType():int
		{
			return this._unitType;
		}
		
		public function veerFrom(arg1:Vec2D, arg2:Number, arg3:Number):void
		{
			angVel = angVel + (this.ov.isLeft(arg1) ? -1 : 1) * this._maxVel * (arg2 + this.feelerDist) / arg3;
			return;
		}
		
		public function set unitType(arg1:int):void
		{
			this._unitType = arg1;
			var loc1:*=Game.getUnitType(this._unitType);
			var loc2:*=new ColorTransform();
			loc2.color = loc1.color;
			this._mc.transform.colorTransform = loc2;
			this._maxVel = loc1.speed;
			this._maxAngVel = this._maxVel * 3;
			this._scaleTime = loc1.agility;
			this.value = loc1.value;
			return;
		}
	}
}